package com.xizi.lotterySystem.controller;


import com.xizi.lotterySystem.common.pojo.CommonResult;
import com.xizi.lotterySystem.controller.param.PageListParam;
import com.xizi.lotterySystem.controller.param.PrizeCreateParam;
import com.xizi.lotterySystem.controller.result.FindPrizeListResult;
import com.xizi.lotterySystem.controller.result.PrizeInfo;
import com.xizi.lotterySystem.service.IPrizeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

//奖品模块
@RestController
@RequestMapping("/prize")
public class PrizeController {

    Logger log = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IPrizeService prizeService;

    /**
     * 奖品创建
     * @param param
     * @param file
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "/create")
    public CommonResult<Long> prizeCreate(@RequestPart("param") @Validated PrizeCreateParam param,
                                          @RequestPart("file") MultipartFile file){
        log.info("create   -------   param:{}",param);
        Long id = prizeService.create(param,file);
        return CommonResult.success(id);
    }

    /**
     * 查询奖品列表
     * @param param
     * @return
     */
    @GetMapping("/find-list")
    public CommonResult<FindPrizeListResult> findList(PageListParam param){
        log.info("findList  -----   param:{}",param);

        Long total = prizeService.getPrizeCount();

        List<PrizeInfo> prizeList = prizeService.getPrizeList(param);

        FindPrizeListResult findPrizeListResult = new FindPrizeListResult();
        findPrizeListResult.setTotal(total);
        findPrizeListResult.setRecords(prizeList);

        return CommonResult.success(findPrizeListResult);
    }

}
